package com.gxa.mall.service;

import com.gxa.mall.dao.LoginDao;
import com.gxa.mall.model.Admin;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {
    @Autowired
    LoginDao loginDao;
    public Admin login(Admin admin) {
        admin.setPassword(DigestUtils.md5Hex(admin.getPassword()));
        return loginDao.login(admin);
    }

    //注册密码加密
    public void register(Admin admin) {
        admin.setPassword(DigestUtils.md5Hex(admin.getPassword()));
         loginDao.register(admin);
    }

    //此方法用于管理员修改密码使用
    public void updatepassword(Admin admin) {
        loginDao.updatepassword(admin);
    }

    /**
     * 注册时验证账号是否已经被注册
     */
    public Integer tocheck(Admin admin) {
      return loginDao.tocheck(admin);
    }

    /**
     * 按账号查询个人信息
     * @param account
     * @return
     */
    public Admin toseekadmin(String account) {
       return loginDao.toseekadmin(account);
    }

    public void updataadinfo(Admin admin) {
        loginDao.updataadinfo(admin);
    }
}
